package ex;

import exceptions.NoAgeException;

class Person{
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        if(age < 0 || age > 200){
            throw new NoAgeException(age+"年龄数值非法");
        }
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class ExceptionDemo4 {

    public static void main(String[] args) {
        Person person = new Person("xiaoming",-20);
        System.out.println("person = " + person);
    }
}
